package realQuestion.tuan;

import java.util.Scanner;

public class Test3 {

    public    int   judge(int[][] cakes,int n,int m){

        int min=Integer.MAX_VALUE;
        for (int i = 0; i <n ; i++)
        {
             int sum1=0;
             int sum2=0;
            for (int j = 0; j < i; j++) {
                for (int k = 0; k <m ; k++) {
                    sum1+=cakes[j][k];
                }
            }

            for (int j = i; j < n; j++) {
                for (int k = 0; k <m ; k++) {
                    sum2+=cakes[j][k];
                }
            }
            int diff=Math.abs(sum1-sum2);
            if (diff<min) {
                min=diff;
            }

        }


        for (int i = 0; i <m ; i++)
        {
            int sum3=0;
            int sum4=0;
            for (int j = 0; j < i; j++) {
                for (int k = 0; k <n ; k++) {
                    sum3+=cakes[k][j];
                }
            }

            for (int j = i; j < m; j++) {
                for (int k = 0; k <n ; k++) {
                    sum4+=cakes[k][j];
                }
            }
            int diff=Math.abs(sum3-sum4);
            if (diff<min) {
                min=diff;
            }

        }
        return min;

    }


    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);

        int n = in.nextInt();
        int m = in.nextInt();

        int[][] cakes = new int[n][m];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cakes[i][j]=in.nextInt();

            }
        }

        Test3 test2 = new Test3();
        System.out.println(test2.judge(cakes,n,m));
    }

}
